<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
com.cap.bts.framework.usermgnt.domain.User user = com.cap.bts.commonfunc.common.util.UserUtil.getCurrentUser();
if(user == null){
	response.addHeader("Set-Cookie", "user=" + request.getParameter("dealerNum") + "; path=/; HttpOnly");
}else{
	response.addHeader("Set-Cookie", "user=" + user.getDealerId() + "; path=/; HttpOnly");
}
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>服务提醒</title>
<%@include file="../include/include.jsp"%>
<script type="text/javascript" src="${jspath}/jquery/jquery-1.8.3.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="${csspath }/datepicker.css"/>
<script type="text/javascript" src="${jspath }/ui.datepicker_zh-CN.js"></script>
<script type="text/javascript" src="${jspath }/jquery.ui.min.js"></script>
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script> 
<script type="text/javascript" src="${layerPath}/layer.js"></script>
</head>
<style>
.icon {
	color: #FFFFFF;
}

.btnLength {
	width: 50px;
}

.checkbox-li {
	display: inline-block;
	width: 100px;
}

.boarder {
	/* //border: 1px solid #DDD; */
}

.text-label {
	width: 120px;
	height: 20px;
	line-height: 20px;
	font-size: 14px;
	font-weight: blod;
	text-align: left;
}

#high10 {
	height: 10px;
}

#high20 {
	height: 20px;
}

#high30 {
	height: 30px;
}

.page_div {
	height: 22px;
	border: 0px solid #F00;
}

.page_div .page_info {
	display: inline-block;
}

.page_div .page_opts {
	float: right;
}

.page_div .page_opts ul {
	list-style: outside none none;
}

#pageNumber2 {
	width: 30px;
}

.page_div .page_opts ul li {
	display: inline-block;
}

.form-control1 {
	width: 100%;
	height: 34px;
	padding: 6px 12px;
	font-size: 14px;
	line-height: 1.42857;
	color: #555;
	background-color: #FFF;
	background-image: none;
	border: 1px solid #CCC;
	border-radius: 0px;
	box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
	transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s
		ease-in-out 0s;
}
</style>
<script type="text/javascript">
	$(function() {
		if ($("#sendAllFlag").attr('checked')) {
			$("input[checkall='checkbox']").each(function() {
				$(this).attr('checked', true)
			});
		} else {
			$("input[checkall='checkbox']").each(function() {
				$(this).attr('checked', false)
			});
		}

		$("#sendAllFlag").click(function() {
			if ($("#sendAllFlag").attr('checked')) {
				$("input[checkall='checkbox']").each(function() {
					$(this).attr('checked', true)
				});
			} else {
				$("input[checkall='checkbox']").each(function() {
					$(this).attr('checked', false)
				});
			}
		});

		var isServiceTypeChecked = false;
		$("#search").click(function() {
			$("input[servicetype='servicetype']").each(function() {
				if ($(this).attr('checked')) {
					isServiceTypeChecked = true;
				};
			});
			if($("#qRemindStartDate").val() == "" || $("#qRemindStartDate").val() == undefined || $("#qRemindStartDate").val() == null){
				jAlert('请选择建议服务日期', '提示');
				return false;
			} 
			layer.load("1");
			$("#search_form").submit();
		});

		$("#submitQuery")
				.click(
						function() {
							/* 
							var tempStart = $("#tempStart").val();
							var tempEnd = $("#tempEnd").val();
							var qRemindStartDate = $("#qRemindStartDate").val();
							var qRemindEndDate = $("#qRemindEndDate").val();
							var startD = new Date(Date.parse(tempStart.replace(/-/g,"/")));
							var endD   = new Date(Date.parse(tempEnd.replace(/-/g,"/")));
							var qstartD = new Date(Date.parse(qRemindStartDate.replace(/-/g,"/")));
							var qendD   = new Date(Date.parse(qRemindEndDate.replace(/-/g,"/")));
							var days = parseInt((qendD.getTime()-qstartD.getTime()) / (1000 * 60 * 60 * 24));
							var daysStart = parseInt((qstartD.getTime()-startD.getTime()) / (1000 * 60 * 60 * 24));
							var daysEnd = parseInt((endD.getTime()-qendD.getTime()) / (1000 * 60 * 60 * 24));
							if(qRemindStartDate == "" || qRemindStartDate == undefined || qRemindStartDate == null){
								jAlert('请输入开始日期', '提示');
								return false;
							}
							
							if(qRemindEndDate == "" || qRemindEndDate == undefined || qRemindEndDate == null){
								jAlert('请输入结束日期', '提示');
								return false;
							}
							
							if(daysStart<0){
								jAlert('开始日期必须大于等于'+tempStart, '提示');
								return false;
							}
							
							if(daysEnd<0){
								jAlert('结束日期必须小于等于'+tempEnd, '提示');
								return false;
							}
							
							if(days < 0){
								jAlert('结束日期必须大于开始日期！', '提示');
								return false;
							} */
							jConfirm(
									"确定发送推送信息?",
									"确认提示",
									function(result) {
										if (result == true) {
											layer.load("1");
											$.ajax({
														url : '${webcontext}/crmdp/dealer/remind/sendRemindMsg',
														type : 'post',
														data : $('form')
																.serialize(),
														success : function(data) {
																layer.closeAll("loading");
															if (!data.result) {
																jAlert(data.errorMsg);
															} else {
																jAlert(
																		data.successMsg,
																		"提示",
																		function() {
																			$("form").submit();
																		});
															}
														},
														error : function(msg) {
															alert(msg);
														}
													})
										}
									});
						});

		$("#historyQuery")
				.click(
						function() {
							window.location.href = "${webcontext}/crmdp/dealer/remind/toRemindHistory?fromPage=remind&isUserHistory=0&dealerNum=${dto.dealerNum}";
						});

		$("#confirmMsgPackage")
				.click(
						function() {
							layer.load(1);
							$
									.ajax({
										url : '${webcontext}/crmdp/dealer/remind/getRemindListSize',
										type : 'post',
										data : $('form').serialize(),
										success : function(data) {
											layer.closeAll();
											if (!data.result) {
												jAlert(data.errorMsg);
											} else {
												if (data.msgPackageSize == 0) {
													jAlert("无充值记录！", "提示",
															function() {
																return false;
															});
												} else {
													layer
															.open({
																type : 2,
																offset : [
																		'10px',
																		'25%' ],
																area : [
																		'400px',
																		'300px' ],
																scrollbar : false,
																title : '短信包充值',
																content : '${webcontext}/crmdp/dealer/remind/toMsgPackageList?dealerNum=' + $("#dealerNum").val(),
																end : function() {
																}
															});
												}
											}
										},
										error : function(msg) {
											layer.closeAll();
											alert(msg);
										}
									})
						})

		$("#showMsgPackageHistory")
				.click(
						function() {
							$
									.ajax({
										url : '${webcontext}/crmdp/dealer/remind/getRemindListSize',
										type : 'post',
										data : $('form').serialize(),
										success : function(data) {
											if (!data.result) {
												jAlert(data.errorMsg);
											} else {
												if (data.msgPackageHistorySize == 0) {
													jAlert("无充值记录！", "提示",
															function() {
																return false;
															});
												} else {
													layer
															.open({
																type : 2,
																offset : [
																		'10px',
																		'25%' ],
																area : [
																		'450px',
																		'300px' ],
																scrollbar : false,
																title : '短信包充值记录',
																content : '${webcontext}/crmdp/dealer/remind/toMsgPackageHistoryList',
																end : function() {
																}
															});
												}
											}
										},
										error : function(msg) {
											alert(msg);
										}
									})
						})

		//选中后该行高亮
		$('tr').bind(
				'click',
				function() {
					if (window.cur)
						window.cur.style.background = "";
					if (window.cur)
						window.cur.style.fontWeight = "normal";
					this.style.background = "#e8e8e8";
					this.style.fontWeight = "bold";
					window.cur = this;
					if ($(this).find("td input[checkall='checkbox']").attr(
							"checked")) {
						$(this).find("td input[checkall='checkbox']").attr(
								"checked", false);
					} else {
						$(this).find("td input[checkall='checkbox']").attr(
								"checked", true);
					}
					return;
				});
		$("td input[checkall='checkbox']").bind('click', function() {
			if ($(this).attr("checked")) {
				$(this).attr("checked", false);
			} else {
				$(this).attr("checked", true);
			}
		})

	});

	function serachBycarPlate(o){
		layer
		.open({
			type : 2,
			offset : [
					'100px',
					'100px' ],
			area : [
					'900px',
					'800px' ],
			scrollbar : false,
			title : '车牌下所有记录',
			content : '${webcontext}/crmdp/dealer/remind/toRemindForCarplate?carPlate=' + encodeURI(encodeURI(o)),
			shadeClose : true,
			end : function() {
			}
		});
	}
	
	function search() {
		search_form.action = "${webcontext}/crmdp/dealer/remind/toRemind";
		document.getElementById("search_form").submit();
	}
	
	function showUserHistory(id, memberName, mobliePhone, carPlate, serviceType) {
		$("#userId").val(id);
		$("#isUserHistory").val("1");
		$("#qHServiceType").val(serviceType);
		$("#qHMemberName").val(memberName);
		$("#qHMobliePhone").val(mobliePhone);
		$("#qHCarPlate").val(carPlate);
		$("#search_form").attr("action",
				"${webcontext}/crmdp/dealer/remind/toRemindHistory");
		$("#search_form").submit();
	}
</script>


<body>
	<form:form id="search_form"
		action="${webcontext}/crmdp/dealer/remind/toRemind" method="post">
		<div style="margin-left: 150px; width: 800px;">
			<div class="boarder">
				<div id="high10"></div>
				<div class="text-label"
					style="display: inline-block; margin-top: 2px;">
					<strong>短信包信息 </strong>
				</div>
				<div class=""
					style="display: inline-block; margin-top: 2px; width: 80px">
					标准余额:</div>
				<div class=""
					style="display: inline-block; margin-top: 2px; width: 80px">
					<label>${remindQuota.defaultQuantity }</label>
				</div>
				<div class=""
					style="display: inline-block; margin-top: 2px; width: 80px">
					充值余额:</div>
				<div class="" style="display: inline-block; margin-top: 2px;">
					<label id="lblpurchaseQuantity">${remindQuota.purchaseQuantity}</label>
				</div>
				<div id="high10"></div>
			</div>
		</div>
		<div id="high10"></div>
		<div style="margin-left: 150px; width: 900px;">
			<div class="boarder">
				<div id="high10"></div>
				<label style="width: 120px"><strong>建议服务日期 </strong></label>
				<%-- <div style="display: none;">
					<input type="text" class="form-control1" id="day" name="day"
						style="width: 45px" maxLength="2" value="${dto.day}">&nbsp;≤<label
						id="maxRemindDays">${maxRemindDays}</label>天 <input type="text"
						class="form-control1" id="afterday" name="afterday"
						style="width: 45px" maxLength="2" value="${dto.afterday}">&nbsp;≤<label
						id="maxAfterRemindDays">${maxAfterRemindDays}</label>天&nbsp;&nbsp;
				</div> --%>
				<input type="hidden" id="tempStart" name="tempStart" value="${ maxRemindDate }">
				<input id="qRemindStartDate" name="qRemindStartDate" class="form-control1 Wdate"
					style="width: 150px" id="startDate" type="text" onclick="WdatePicker({dateFmt:'yyyy-MM'})" readonly="readonly"
					value='<core:if test="${empty dto.qRemindStartDate}">${ maxRemindDate }</core:if><core:if test="${!empty dto.qRemindStartDate}">${fn:substring(dto.qRemindStartDate,0,7)}</core:if>' />
				<div id="high10"></div>
				<div id="high10"></div>
				<div>
					<label style="width: 120px"></label>
					<input type="radio" name="reSendFlag" value="notReSendFlag" <core:if test='${dto.reSendFlag == "notReSendFlag"}'>checked</core:if>/>仅显示未发送
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="radio" name="reSendFlag" value="reSendFlag" <core:if test='${dto.reSendFlag == "reSendFlag"}'>checked</core:if>/>仅显示已发送
				</div>
				<div>
					<label style="width: 120px"></label>
					<input type="radio" name="potentialLossFlag" value="potentialLossFlag" <core:if test='${dto.potentialLossFlag == "potentialLossFlag"}'>checked</core:if>/>仅显示重复消费客户
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="radio" name="potentialLossFlag" value="notPotentialLossFlag" <core:if test='${dto.potentialLossFlag == "notPotentialLossFlag"}'>checked</core:if>/>仅显示潜在消费客户
				</div>
				<div id="high10"></div>
				<div id="high10"></div>
			</div>
			<div class="boarder">
				<div id="high10"></div>
				<label style="width: 120px"><strong>客户信息 </strong></label>&nbsp;姓名&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="text" class="form-control1" id="qMemberName"
					name="qMemberName" style="width: 150px" value="${dto.qMemberName}">&nbsp;&nbsp;&nbsp;
				&nbsp;手机&nbsp;&nbsp;&nbsp;&nbsp; <input type="text"
					class="form-control1" id="qMobliePhone" name="qMobliePhone"
					style="width: 150px" value="${dto.qMobliePhone}">&nbsp;&nbsp;&nbsp;
				&nbsp;车牌&nbsp;&nbsp;&nbsp;&nbsp; <input type="text"
					class="form-control1" id="qCarPlate" name="qCarPlate"
					style="width: 150px" value="${dto.qCarPlate}">&nbsp;&nbsp;&nbsp;
				&nbsp;
				<!-- 个人推送历史查询参数 -->
				<input type="hidden" id="dealerNum" name="dealerNum" value="${dto.dealerNum}">
				<input type="hidden" id="qHServiceType" name="qHServiceType">
				<input type="hidden" id="qHMemberName" name="qHMemberName">
				<input type="hidden" id="qHMobliePhone" name="qHMobliePhone">
				<input type="hidden" id="qHCarPlate" name="qHCarPlate"> <input
					type="hidden" id="userId" name="id" value=""> <input
					type="hidden" id="isUserHistory" name="isUserHistory">
				<div id="high10"></div>
			</div>
				<div class="boarder">
				<div class="text-label"
					style="display: inline-block; margin-top: 2px;">
					<label style="width: 110px"><strong>服务项目 </strong></label>
				</div>
				<div class="checkbox "
					style="width: 400px; height: 80px; display: inline-block;">
					<ul>
						<core:forEach items="${serviceTypeDtos}" var="serviceTypeList"
							varStatus="status">
							<li class="checkbox-li"><input servicetype="servicetype"
								name="serviceType[${status.index}].serviceFlag" type="checkbox"
								<core:if test="${serviceTypeList.serviceFlag}">checked</core:if>>
								<input name="serviceType[${status.index}].code" type="hidden"
								value="${serviceTypeList.code }"> <input
								name="serviceType[${status.index}].serviceType" type="hidden"
								value="${serviceTypeList.serviceType }">
								${serviceTypeList.serviceType}</li>
							<core:if test="${status.index eq 4 }">
								</br>
							</core:if>
						</core:forEach>
					</ul>
				</div>
			</div>
			<div>
				<div id="high10"></div>
				<div style="padding-left: 150px">
					<button id="search" type="button" class="btn btn-success">
						<i class="glyphicon glyphicon-search" style="color: #FFFFFF"></i>&nbsp;查询
					</button>
					<button type="reset" class="btn btn-success">
						<i class="glyphicon glyphicon-trash" style="color: #FFFFFF"></i>&nbsp;重置
					</button>
					<button type="button" id="historyQuery" class="btn btn-success">
						<i class="glyphicon glyphicon-list-alt" style="color: #FFFFFF"></i>&nbsp;查看历史&nbsp;
					</button>
					<button type="button" id="confirmMsgPackage"
						class="btn btn-success">&nbsp;短信充值&nbsp;</button>
					<button type="button" id="showMsgPackageHistory"
						class="btn btn-success">&nbsp;充值记录&nbsp;</button>
				</div>
				<div id="high10"></div>
			</div>
			<div id="high10"></div>
		</div>
		<div style="margin-left: 10px">
			<input type="checkbox" id="sendAllFlag" name="sendAllFlag"
				<core:if test='${dto.sendAllFlag}'>checked</core:if>><strong>全选</strong>
<!-- 				<strong><font style="color: red;">(红色显示为潜在流失客户)</font></strong> -->
		</div>
		<div class="cantainer">
			<div>
				<table class="table" style="font-size: 80%; width: 100%;">
					<thead>
						<tr>
							<th><nobr>选中</nobr></th>
							<th><nobr>已提醒次数</nobr></th>
							<th>姓名</th>
							<th>手机</th>
							<th>车牌</th>
							<th><nobr>建议保养项目</nobr></th>
							<th><nobr>建议服务日期</nobr></th>
							<th><nobr>建议服务里程</nobr></th>
							<th><nobr>上次服务日期</nobr></th>
							<th><nobr>上次服务里程</nobr></th>
						</tr>
					</thead>
					<tbody>
						<core:forEach items="${list}" var="list" varStatus="status">
							<tr>
								<td><input type="checkbox" checkall="checkbox"
									name="remindList[${status.index}].checkFlag"> <input
									type="hidden" name="remindList[${status.index}].memberName"
									value="${list.memberName }"> <input type="hidden"
									name="remindList[${status.index}].mobliePhone"
									value="${list.mobliePhone }"> <input type="hidden"
									name="remindList[${status.index}].carPlate"
									value="${list.carPlate}"> <input type="hidden"
									name="remindList[${status.index}].nextCalcMileage"
									value="${ list.nextCalcMileage}"> <input type="hidden"
									name="remindList[${status.index}].nextCalcDate"
									value="${ fn: substring (list.nextCalcDate,0,10)}"> <input
									type="hidden" name="remindList[${status.index}].id"
									value="${list.id}"> <input type="hidden"
									name="remindList[${status.index}].remindTimes"
									value="${list.remindTimes}"> <input type="hidden"
									name="remindList[${status.index}].maintenanceItem"
									value="${list.maintenanceItem}"> <input type="hidden"
									name="remindList[${status.index}].lastPartBrand"
									value="${list.lastPartBrand}"></td>
								<core:if test="${list.isPotentialLoss == 1}">
									<td><font style="color: red;"><a href="javascript:void(0)"
										onclick="showUserHistory('${list.id }','${list.memberName }','${list.mobliePhone }','${list.carPlate }','${list.maintenanceItem  }')">
											${list.remindTimes}</a></font></td>
									<td><font style="color: red;">${list.memberName }</font></td>
									<td><font style="color: red;">${list.mobliePhone }</font></td>
									<td><a id="serachBycarPlate" style="cursor:pointer;" onclick="serachBycarPlate('${list.carPlate}')" title="该车牌相关推送信息">${list.carPlate}</a></td>
									<td><font style="color: red;">${list.maintenanceItem }</font></td>
									<td><font style="color: red;"><core:if
											test="${fn: substring (list.nextCalcDate,0,10) eq 'null'}"></core:if>
										<core:if
											test="${fn: substring (list.nextCalcDate,0,10) ne 'null'}">${ fn: substring (list.nextCalcDate,0,10)}</core:if>
										</font>
									</td>
									<td><font style="color: red;"><core:if test="${list.nextCalcDate eq 'null'}"></core:if>
										<core:if test="${ list.nextCalcMileage ne 'null'}">${ list.nextCalcMileage}</core:if>
										</font>
									</td>
									<td><font style="color: red;"><core:if
											test="${ fn: substring (list.lastMaintenanceDate,0,10) eq 'null'}"></core:if>
										<core:if
											test="${ fn: substring (list.lastMaintenanceDate,0,10) ne 'null'}">${ fn: substring (list.lastMaintenanceDate,0,10)}</core:if>
										</font>
									</td>
									<td><font style="color: red;"><core:if
											test="${list.lastMaintenanceMileage eq 'null'}"></core:if> <core:if
											test="${ list.lastMaintenanceMileage ne 'null'}">${ list.lastMaintenanceMileage}</core:if>
										</font>
									</td>
								</core:if>
								<core:if test="${list.isPotentialLoss == 0}">
									<td><a href="javascript:void(0)"
										onclick="showUserHistory('${list.id }','${list.memberName }','${list.mobliePhone }','${list.carPlate }','${list.maintenanceItem  }')">
											${list.remindTimes}</a></td>
									<td>${list.memberName }</td>
									<td>${list.mobliePhone }</td>
									<td><a id="serachBycarPlate" style="cursor:pointer;" onclick="serachBycarPlate('${list.carPlate}')" title="该车牌相关推送信息">${list.carPlate}</a></td>
									<td>${list.maintenanceItem }</td>
									<td><core:if
											test="${fn: substring (list.nextCalcDate,0,10) eq 'null'}"></core:if>
										<core:if
											test="${fn: substring (list.nextCalcDate,0,10) ne 'null'}">${ fn: substring (list.nextCalcDate,0,10)}</core:if>
									</td>
									<td><core:if test="${list.nextCalcDate eq 'null'}"></core:if>
										<core:if test="${ list.nextCalcMileage ne 'null'}">${ list.nextCalcMileage}</core:if>
									</td>
									<td><core:if
											test="${ fn: substring (list.lastMaintenanceDate,0,10) eq 'null'}"></core:if>
										<core:if
											test="${ fn: substring (list.lastMaintenanceDate,0,10) ne 'null'}">${ fn: substring (list.lastMaintenanceDate,0,10)}</core:if>
									</td>
									<td><core:if
											test="${list.lastMaintenanceMileage eq 'null'}"></core:if> <core:if
											test="${ list.lastMaintenanceMileage ne 'null'}">${ list.lastMaintenanceMileage}</core:if>
									</td>
								</core:if>
							</tr>
						</core:forEach>
					</tbody>
				</table>
			</div>
			<div class="page_div">
				<%@include file="../common/page.jsp"%>
			</div>
			<div style="text-align: center;">
				<button type="button" id="submitQuery" class="btn btn-success">
					<i class="glyphicon glyphicon-upload" style="color: #FFFFFF"></i>&nbsp;发&nbsp;&nbsp;送&nbsp;
				</button>
			</div>
		</div>
	</form:form>
</body>
</html>